from rest_framework import mixins
from rest_framework.decorators import action
from rest_framework.response import Response
from rest_framework.viewsets import GenericViewSet

from apps.club_system.club.filters import AccountFilter
from apps.club_system.club.serializers.account import AccountSerializer, AccountListSerializer
from apps.common.account.models import Account
from apps.club_system.club.models import ClubMember
from utils.common import Pagination
from apps.common.school.models import Faculty

yhjs_ls = ['本科生', '继续教育学生', '联合培养学生', '研究生']
zt_ls = ['在岗', '在读']


class AccountAdministerViewSet(GenericViewSet):
    """账号表视图"""
    # values = ClubMember.objects.all().values_list('account_id', flat=True)
    # queryset = Account.objects.filter(id__in=list(values))
    queryset = Account.objects.all().order_by('updated_time')
    serializer_class = AccountSerializer
    filter_class = AccountFilter
    pagination_class = Pagination
    ordering_fields = ('id', 'created_time', 'updated_time')

    # @action(methods=['get'], detail=False, url_path='faculty_list')
    # def get_faculty(self, request):
    #     queryset = Faculty.objects.all().values('id', 'faculty_title').order_by('id')
    #     return Response(queryset)

    @action(methods=['get'], detail=False, url_path='teacher_list')
    def get_teacher(self, request):
        queryset = self.filter_queryset(self.get_queryset())
        queryset = queryset.filter(type='正式教职工', status='在岗')
        res_data = queryset.values('id', 'realname', 'username', 'faculty_title', 'politics_status').order_by('id')
        return Response(res_data)

    @action(methods=['get'], detail=False, url_path='student_list')
    def get_student(self, request):
        queryset = self.filter_queryset(self.get_queryset())
        queryset = queryset.filter(type__in=yhjs_ls, status='在读')
        res_data = queryset.values('id', 'realname', 'username', 'faculty_title', 'politics_status').order_by('id')
        return Response(res_data)
